import { Button, Tooltip } from 'antd';
import { WasteMaterialsAPI } from '../common/type';
import pageStyles from '@/common/pageLayout.less';
import { DictionaryRenderFun, formatDecimalFour } from '../../Acommon';
import { tableMoreBtnConfig } from '@/utils/myutilConfig';
import { Fragment } from 'react';
import { CloseCircleOutlined } from '@ant-design/icons';
import { getTenantID, removeDateHmsStr } from '@/utils';
import { ILoadMapTypeAll } from '@/common';

/**操作按钮的显示*/
const Operation = (curRes: Record<string, any>, operateFuns: any, record: Record<string, any>) => {
  let operationArray: any = [];

  /** 一个按钮都没有时展示*/
  const Disable = (
    <Fragment key={record?.id + '--Disable'}>
      <Button style={{ color: '#000' }} className="manageBtntTxtStyle" type={'link'} size={'small'} disabled>
        --
      </Button>
    </Fragment>
  );

  /** 更多按钮配置 */
  const otherBtnConfig: any[] = [
    {
      icon: <CloseCircleOutlined />,
      btnName: '报废',
      clickFnc: operateFuns,
      clickType: 'onCancel',
      isVisible: record?.assetState == `${getTenantID()}${ILoadMapTypeAll.ASSET_STATUS}1007`, // 0 待报废
    },
  ];
  const ohterBtn = tableMoreBtnConfig(otherBtnConfig, record);
  operationArray = ohterBtn;
  operationArray = operationArray?.filter((itemBtn: any) => itemBtn);
  return operationArray && operationArray?.length > 0 ? operationArray : [Disable];
};

/**
 * 表格信息 展示和操作
 * @returns
 */
const getTableColumns = (
  /** 资源权限参数 */
  curRes: Record<string, any>,
  operateFuns,
) => {
  return [
    {
      title: '物资编号',
      dataIndex: 'materialCode',
      key: 'materialCode',
      width: 150,
      fixed: 'left',
      visible: true,
      unDrag: true,
      sorter: (a: any, b: any) => (a.materialCode > b.materialCode ? 1 : -1),
      render: (text: string, record: Record<string, any>) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '物资名称',
      dataIndex: 'assetName',
      key: 'assetName',
      width: 150,
      fixed: 'left',
      ellipsis: {
        showTitle: true,
      },
      visible: true,
      unDrag: true,
      sorter: (a: any, b: any) => (a.assetName > b.assetName ? 1 : -1),
      render: (text: string, record: Record<string, any>) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '物资种类',
      dataIndex: 'type',
      key: 'type',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.type > b.type ? 1 : -1),
      render: (text: string | number) => {
        return (
          <Tooltip title={text == '0' ? '材料' : text == '1' ? '资产' : '--'}>
            <div className={pageStyles['over-flow-hidden']}>{text == '0' ? '材料' : text == '1' ? '资产' : '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '物资分类',
      dataIndex: 'assetClassName',
      key: 'assetClassName',
      width: 150,
      ellipsis: {
        showTitle: true,
      },
      visible: true,
      sorter: (a: any, b: any) => (a.assetClassName > b.assetClassName ? 1 : -1),
      render: (text: number | null) => DictionaryRenderFun({ text, isState: false }),
    },
    {
      title: '物资状态',
      dataIndex: 'assetStateName',
      key: 'assetStateName',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.assetStateName > b.assetStateName ? 1 : -1),
      render: (text: number | null) => DictionaryRenderFun({ text, isState: false }),
    },
    {
      title: '品牌',
      dataIndex: 'brandType',
      key: 'brandType',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.brandType > b.brandType ? 1 : -1),
      render: (text: number | null) => DictionaryRenderFun({ text, isState: false }),
    },
    {
      title: '规格型号',
      dataIndex: 'paramsInfo',
      key: 'paramsInfo',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.paramsInfo > b.paramsInfo ? 1 : -1),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '数量',
      dataIndex: 'quantityOrArea',
      key: 'quantityOrArea',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.quantityOrArea > b.quantityOrArea ? 1 : -1),
      render: (text: string | number) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text === 0 || text ? text : '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '计量单位',
      dataIndex: 'unitOfMeasurementName',
      key: 'unitOfMeasurementName',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.unitOfMeasurementName > b.unitOfMeasurementName ? 1 : -1),
      render: (text: number | null) => DictionaryRenderFun({ text, isState: false }),
    },
    {
      title: '单价（元）',
      dataIndex: 'assetValue',
      key: 'assetValue',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.assetValue > b.assetValue ? 1 : -1),
      render: (text: string | number) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || text == 0 ? formatDecimalFour(text) : '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '总价（元）',
      dataIndex: 'totalValue',
      key: 'totalValue',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.totalValue > b.totalValue ? 1 : -1),
      render: (text: string | number) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || text == 0 ? formatDecimalFour(text) : '--'}</div>
          </Tooltip>
        );
      },
    },
    // {
    //   title: '报废数量',
    //   dataIndex: 'repealNum',
    //   key: 'repealNum',
    //   width: 150,
    //   visible: true,
    //   sorter: (a: any, b: any) => (a.repealNum > b.repealNum ? 1 : -1),
    //   render: (text: string | number) => {
    //     return (
    //       <Tooltip title={text}>
    //         <div className={pageStyles['over-flow-hidden']}>{text || text == 0 ? text : '--'}</div>
    //       </Tooltip>
    //     );
    //   },
    // },
    {
      title: '报废时间',
      dataIndex: 'cancelTime',
      key: 'cancelTime',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.cancelTime > b.cancelTime ? 1 : -1),
      render: (text: string) => <span>{removeDateHmsStr(text)}</span>,
    },
    {
      title: '报废部门',
      dataIndex: 'cancelDepartmentName',
      key: 'cancelDepartmentName',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.cancelDepartmentName > b.cancelDepartmentName ? 1 : -1),
      render: (text: string | number) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || text == 0 ? text : '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '报废状态',
      dataIndex: 'isScrap',
      key: 'isScrap',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.isScrap > b.isScrap ? 1 : -1),
      render: (text: string | number) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text ? (text == '0' ? '待报废' : '已报废') : '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '操作',
      dataIndex: 'operation',
      key: 'operation',
      width: 180,
      visible: true,
      unDrag: true,
      fixed: 'right',
      render: (text: string | null, record: Record<string, any>) => {
        return <div style={{ display: 'flex' }}>{Operation(curRes, operateFuns, record)}</div>;
      },
    },
  ];
};

export { getTableColumns };
